//
//  VCMyHeaderView.m
//  VCShop
//
//  Created by VoyageCN on 16/8/17.
//  Copyright © 2016年 VoyageCN. All rights reserved.
//

#import "VCMyHeaderView.h"
#import "VCRegisterViewController.h"


@interface VCMyHeaderView ()
@property (nonatomic, strong) UIView *headerView;
// 背景图片
@property (nonatomic, strong) UIImageView *backImageView;
// 注册button
@property (nonatomic, strong) UIButton *registerBtn;
// 登录button
@property (nonatomic, strong) UIButton *loginBtn;

@end

@implementation VCMyHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    
    if (self) {
        
        [self addSubview:self.headerView];
        [self.headerView addSubview:self.backImageView];
        [_headerView addSubview:self.loginBtn];
        [_headerView addSubview:self.registerBtn];

    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    __weak typeof (self) weakSelf = self;
    
    [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.top.equalTo(weakSelf);
        make.height.equalTo(@150);
    }];
    
    [_backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(weakSelf.headerView).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    [_registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(weakSelf.headerView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(50, 30));
        make.centerX.equalTo(weakSelf.headerView.mas_centerX).offset(60);
    }];
    
    [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(weakSelf.headerView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(50, 30));
        make.centerX.equalTo(weakSelf.headerView.mas_centerX).offset(-60);
    }];
}

- (UIView *)headerView {
    
    if (!_headerView) {
        
        _headerView = [[UIView alloc] init];
    }
    return _headerView;
}

- (UIImageView *)backImageView {
    
    if (!_backImageView) {
        
        _backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"我的背景"]];
    }
    return _backImageView;
}

- (UIButton *)registerBtn {
    
    if (!_registerBtn) {
        
        _registerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_registerBtn setTitle:@"注册" forState:UIControlStateNormal];
        [_registerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_registerBtn setBackgroundColor:[UIColor clearColor]];
        [_registerBtn addTarget:self action:@selector(registerAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _registerBtn;
}

- (UIButton *)loginBtn {
    
    if (!_loginBtn) {
        
        _loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        [_loginBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_loginBtn setBackgroundColor:[UIColor clearColor]];
        [_loginBtn addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _loginBtn;
}

#pragma mark - Action

- (void)pushRegisterViewController {
    
}

- (void)registerAction {
    if (_registerBlock) {
        _registerBlock();
    }
}

- (void)loginAction {
    if (_loginBlock) {
        _loginBlock();
    }
    
}


@end
